#include <stdio.h>
#define TABSIZE(array)  (sizeof(array)/sizeof(array[0]))

int a[] = {10, 5, 2, 4, 7};

void insert_sort(void)
{
    int i, j, key;
    for (j = 1; j < TABSIZE(a); j++) {
        printf("#%2d>", j);
        for (i = 0; i < TABSIZE(a); i++)
            printf(" %2d", a[i]);
        putchar('\n');
        key = a[j];
        for (i = j - 1; i >= 0 && a[i] > key; i--)
            a[i+1] = a[i];
        a[i+1] = key;
    }
    printf("#%2d>", j);
    for (i = 0; i < TABSIZE(a); i++)
        printf(" %2d", a[i]);
    putchar('\n');
}

int main(void)
{
    insert_sort();
    return 0;
}

